# 元组取值
def tuple_get_value():
    my_tuple = (1, 'hello', 3.15, True)
    print(my_tuple)
    print('my_tuple元组的第二个元素为：', my_tuple[1])
    # 获取元组所有元素
    t1, t2, t3, t4 = my_tuple
    print(f'my_tuple元组的所有元素为：{t1}, {t2}, {t3}, {t4}')
    print('--------tuple_get_value函数执行结束！----------')


def tuple_get_lengh():
    my_tuple = (1, 'hello', 3.15, True)
    print(my_tuple)
    print('元组my_tuple的长度为：', len(my_tuple))
    print('--------tuple_get_lengh函数执行结束！----------')


def tuple_suoyin():
    try:
        my_tuple = (1, 'hello', 3.15, True)
        print(my_tuple)
        print(my_tuple[1])
        print(my_tuple[-1])
        print(my_tuple[-2])
        # 超出索引，会抛出异常
        # print(my_tuple[100])
    except Exception as e:
        print('程序执行出错，抛出异常：', e)
    print('--------tuple_suoyin函数执行结束！----------')


def tuple_qiepian():
    try:
        my_tuple = (1, 'hello', 3.15, True, 'orange', 4, 2, 5, 8, 2)
        print(my_tuple)
        print(my_tuple[2:5])
        print(my_tuple[2:])
        print(my_tuple[:4])
        print(my_tuple[:])
        print(my_tuple[1:7:2])
        print(my_tuple[::-1])
        print(my_tuple[::-2])
        print(my_tuple[::2])
        # 超出索引，会抛出异常
    except Exception as e:
        print('程序执行出错，抛出异常：', e)
    print('--------tuple_qiepian函数执行结束！----------')


if __name__ == '__main__':
    # tuple_get_value()
    # tuple_get_lengh()
    # tuple_suoyin()
    tuple_qiepian()